home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 125 / Computer Shopper CD-ROM Issue 125 (1998-07)(Dennis Publishing).iso / Business / Dazzler / DAZZLER.Z / CComboBox.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-26  |  5.0 KB  |  231 lines

  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Point;
  5. import java.awt.Polygon;
  6. import java.awt.Rectangle;
  7. import java.awt.Toolkit;
  8.  
  9. class CComboBox {
  10.    static final int BUTTON_WIDTH = 15;
  11.    static final Point TEXT_SPACING = new Point(5, 4);
  12.    private int m_nFlags;
  13.    private int m_nButtonState;
  14.    private CRect m_rcDraw;
  15.    private CRect m_rcText;
  16.    private CRect m_rcButton;
  17.    private CRect m_rcListBox;
  18.    private Font m_Font;
  19.    private Color m_rgbFg;
  20.    private Color m_rgbBg;
  21.    private String m_strSelection;
  22.    private boolean m_bHasFocus;
  23.    private boolean m_bListVisible;
  24.    private CListBox m_ListBox;
  25.  
  26.    public boolean ProcessMouseMove(Point var1) {
  27.       if (this.m_rcListBox.inside(var1.x, var1.y)) {
  28.          this.m_ListBox.ProcessMouseMove(var1);
  29.       } else if (this.m_rcButton.inside(var1.x, var1.y) && Utils.StateTest(this.m_nButtonState, 8) && Utils.StateTest(this.m_nButtonState, 4)) {
  30.          this.m_nButtonState = Utils.StateClear(this.m_nButtonState, 4);
  31.          this.DrawButton(Globals.thePresView.GetDC());
  32.       } else if (!this.m_rcButton.inside(var1.x, var1.y) && Utils.StateTest(this.m_nButtonState, 8) && !Utils.StateTest(this.m_nButtonState, 4)) {
  33.          this.m_nButtonState = Utils.StateSet(this.m_nButtonState, 4);
  34.          this.DrawButton(Globals.thePresView.GetDC());
  35.       }
  36.  
  37.       return false;
  38.    }
  39.  
  40.    public void SetRect(CRect var1) {
  41.       int var2 = this.m_rcListBox.height;
  42.       this.m_rcDraw.reshape(var1);
  43.       this.SetRegions();
  44.       this.m_rcListBox.height = var2;
  45.    }
  46.  
  47.    public void HideList() {
  48.       this.m_bListVisible = false;
  49.    }
  50.  
  51.    public void DrawControl() {
  52.       this.DrawControl(Globals.thePresView.GetDC(), this.m_rcDraw);
  53.    }
  54.  
  55.    public void DrawControl(Graphics var1, CRect var2) {
  56.       if (var1 == null) {
  57.          var1 = Globals.thePresView.GetDC();
  58.       }
  59.  
  60.       if (var2 == null) {
  61.          var2 = this.m_rcDraw;
  62.       }
  63.  
  64.       if (var1 != null && var2 != null) {
  65.          Graphics var3 = var1.create();
  66.          var3.clipRect(var2.x, var2.y, var2.width, var2.height);
  67.          var3.setFont(this.m_Font);
  68.          int var4 = var3.getFontMetrics().getAscent();
  69.          var3.setColor(this.m_rgbBg);
  70.          var3.fillRect(this.m_rcText.x, this.m_rcText.y, this.m_rcText.width, this.m_rcText.height);
  71.          var3.setColor(Color.black);
  72.          var3.drawRect(this.m_rcText.x, this.m_rcText.y, this.m_rcDraw.width - 1, this.m_rcText.height - 1);
  73.          if (this.m_strSelection.length() > 0) {
  74.             var3.setColor(this.m_rgbFg);
  75.             var3.drawString(this.m_strSelection, this.m_rcText.x + TEXT_SPACING.x, this.m_rcText.y + var4 + TEXT_SPACING.y);
  76.          }
  77.  
  78.          this.DrawButton(var3);
  79.          if (this.m_bListVisible) {
  80.             this.m_ListBox.DrawControl(var3, this.m_rcListBox);
  81.          }
  82.       }
  83.  
  84.    }
  85.  
  86.    public boolean ProcessMouseUp(Point var1) {
  87.       this.m_nButtonState = 0;
  88.       if (this.m_bListVisible) {
  89.          if (this.m_rcListBox.inside(var1.x, var1.y)) {
  90.             this.m_ListBox.ProcessMouseUp(var1);
  91.             this.m_strSelection = this.m_ListBox.GetSel();
  92.             this.m_bListVisible = false;
  93.             Globals.thePresView.Render(this.m_rcDraw);
  94.             Globals.thePresView.Draw((Graphics)null, this.m_rcDraw);
  95.          } else if (this.m_rcButton.inside(var1.x, var1.y)) {
  96.             this.DrawButton(Globals.thePresView.GetDC());
  97.          }
  98.       }
  99.  
  100.       this.m_bHasFocus = false;
  101.       return false;
  102.    }
  103.  
  104.    public boolean HasFocus() {
  105.       return this.m_bHasFocus;
  106.    }
  107.  
  108.    CComboBox(int var1, CRect var2) {
  109.       this.m_nFlags = var1;
  110.       this.m_rcDraw = var2;
  111.       this.m_rcText = new CRect();
  112.       this.m_rcButton = new CRect();
  113.       this.m_rcListBox = new CRect();
  114.       this.m_Font = new Font("Helvetica", 0, 20);
  115.       this.m_rgbFg = new Color(0, 0, 0);
  116.       this.m_rgbBg = new Color(255, 255, 255);
  117.       this.m_strSelection = "";
  118.       this.m_bHasFocus = false;
  119.       this.m_bListVisible = false;
  120.       int var3 = 17;
  121.       if ((var1 & 4) != 0) {
  122.          var3 |= 4;
  123.       }
  124.  
  125.       this.m_ListBox = new CListBox(var3, this.m_rcListBox);
  126.       this.m_ListBox.SetFont(this.m_Font);
  127.       this.SetRegions();
  128.    }
  129.  
  130.    public void SetBgColour(Color var1) {
  131.       this.m_rgbBg = var1;
  132.       this.m_ListBox.SetBgColour(var1);
  133.    }
  134.  
  135.    public void SetFgColour(Color var1) {
  136.       this.m_rgbFg = var1;
  137.       this.m_ListBox.SetFgColour(var1);
  138.    }
  139.  
  140.    public void SetRegions() {
  141.       int var1 = Toolkit.getDefaultToolkit().getFontMetrics(this.m_Font).getHeight();
  142.       this.m_rcText.reshape(this.m_rcDraw.x, this.m_rcDraw.y, this.m_rcDraw.width - 15, var1 + 2 * TEXT_SPACING.y);
  143.       this.m_rcButton.reshape(this.m_rcDraw.x + (this.m_rcDraw.width - 15), this.m_rcDraw.y, 15, this.m_rcText.height);
  144.       this.m_rcListBox.reshape(this.m_rcDraw.x, this.m_rcDraw.y + this.m_rcText.height + 1, this.m_rcDraw.width, 0);
  145.       this.m_rcDraw.height = this.m_rcText.height + this.m_rcListBox.height + 1;
  146.    }
  147.  
  148.    private void DrawButton(Graphics var1) {
  149.       Color var2 = Color.white;
  150.       Color var3 = Color.darkGray;
  151.       byte var4 = 0;
  152.       var1.setColor(Color.black);
  153.       var1.drawRoundRect(this.m_rcButton.x, this.m_rcButton.y, this.m_rcButton.width - 1, this.m_rcButton.height - 1, 2, 2);
  154.       var1.setColor(Color.lightGray);
  155.       var1.fillRect(this.m_rcButton.x + 2, this.m_rcButton.y + 2, this.m_rcButton.width - 4, this.m_rcButton.height - 4);
  156.       if (Utils.StateTest(this.m_nButtonState, 8) && !Utils.StateTest(this.m_nButtonState, 4)) {
  157.          var2 = Color.darkGray;
  158.          var3 = Color.white;
  159.          var4 = 1;
  160.       }
  161.  
  162.       var1.setColor(var2);
  163.       var1.drawLine(this.m_rcButton.x + 1, this.m_rcButton.y + 1, this.m_rcButton.x + this.m_rcButton.width - 2, this.m_rcButton.y + 1);
  164.       var1.drawLine(this.m_rcButton.x + 1, this.m_rcButton.y + 1, this.m_rcButton.x + 1, this.m_rcButton.y + this.m_rcButton.height - 3);
  165.       var1.setColor(var3);
  166.       var1.drawLine(this.m_rcButton.x + 1, this.m_rcButton.y + this.m_rcButton.height - 2, this.m_rcButton.x + this.m_rcButton.width - 2, this.m_rcButton.y + this.m_rcButton.height - 2);
  167.       var1.drawLine(this.m_rcButton.x + this.m_rcButton.width - 2, this.m_rcButton.y + 2, this.m_rcButton.x + this.m_rcButton.width - 2, this.m_rcButton.y + this.m_rcButton.height - 2);
  168.       CRect var5 = new CRect();
  169.       Polygon var6 = new Polygon();
  170.       ((Rectangle)var5).reshape(this.m_rcButton.x + 4 + var4, this.m_rcButton.y + (this.m_rcButton.height - 4) / 2 + var4, 7, 4);
  171.       var6.addPoint(var5.x, var5.y);
  172.       var6.addPoint(var5.x + var5.width, var5.y);
  173.       var6.addPoint(var5.x + var5.width / 2, var5.y + var5.height);
  174.       var1.setColor(Color.black);
  175.       var1.fillPolygon(var6.xpoints, var6.ypoints, var6.npoints);
  176.    }
  177.  
  178.    public boolean ProcessMouseDown(Point var1) {
  179.       if (this.m_bListVisible) {
  180.          if (this.m_rcListBox.inside(var1.x, var1.y)) {
  181.             this.m_ListBox.ProcessMouseDown(var1);
  182.             this.m_strSelection = this.m_ListBox.GetSel();
  183.             this.DrawControl();
  184.          }
  185.  
  186.          this.m_bListVisible = false;
  187.          this.m_bHasFocus = true;
  188.          Globals.thePresView.Render(this.m_rcListBox);
  189.          Globals.thePresView.Draw((Graphics)null, this.m_rcListBox);
  190.       } else if (this.m_rcButton.inside(var1.x, var1.y)) {
  191.          this.m_nButtonState = Utils.StateSet(this.m_nButtonState, 8);
  192.          this.m_bListVisible = true;
  193.          this.m_bHasFocus = true;
  194.          this.DrawButton(Globals.thePresView.GetDC());
  195.          this.m_ListBox.DrawControl();
  196.       } else if (this.m_rcText.inside(var1.x, var1.y)) {
  197.          this.m_bListVisible = true;
  198.          this.m_bHasFocus = true;
  199.          this.m_ListBox.DrawControl();
  200.       }
  201.  
  202.       return false;
  203.    }
  204.  
  205.    public void SetSelections(String var1, String var2) {
  206.       this.m_strSelection = this.m_ListBox.SetSelections(var1, var2);
  207.    }
  208.  
  209.    public void SetFont(Font var1) {
  210.       this.m_Font = var1;
  211.       this.m_ListBox.SetFont(var1);
  212.       this.SetRegions();
  213.    }
  214.  
  215.    public boolean SelectionValid() {
  216.       return this.m_strSelection.length() == 0 || this.m_ListBox.FindItem(this.m_strSelection);
  217.    }
  218.  
  219.    public String GetSel() {
  220.       return this.m_strSelection;
  221.    }
  222.  
  223.    public void FillListBox(String var1, String var2) {
  224.       this.m_rcListBox.height = this.m_ListBox.FillListBox(var1, var2) + 1;
  225.    }
  226.  
  227.    public boolean ListVisible() {
  228.       return this.m_bListVisible;
  229.    }
  230. }
  231.